<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>

<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
    <?php if (count($_items)):?>
		<div class="review-list-head">
			<?php echo $this->getLayout()->createBlock('rating/entity_detailed')->toHtml() ?>
			<div class="review-list-head-right">
				<div class="average-review-t">Average Customer Review</div>
				<?php echo $this->getLayout()->createBlock('review/helper')->getSummaryHtml($this->getProduct(), 'short', true)?>
				<div class="create-review"></div>
			</div>
		</div>
        <dl>
        <?php $i=1; foreach ($_items as $_review):?>
			<?php if($i!=1):?>
            <dt class="dashed"></dt>
            <?php endif; ?>
            <dd>
                <?php $_votes = $_review->getRatingVotes(); ?>
                <?php if (count($_votes)): ?>
				<?php
					$percent = 0;
					foreach ($_votes as $_vote){
						$percent += $_vote->getPercent();
					}
					$percent = $percent/count($_votes);
				?>
                <table class="ratings-table">
                    <col width="80" />
                    <col />
                    <tbody>
                        <tr>
                            <td>
                                <div class="rating-box">
                                    <div class="rating" style="width:<?php echo $percent ?>%;"></div>
                                </div>
                            </td>
							<td>
								<strong><?php echo $this->htmlEscape($_review->getTitle()) ?></strong>,
								<?php echo $this->formatDate($_review->getCreatedAt(),'long'); ?>
							</td>
                        </tr>
                    </tbody>
                </table>
                <?php endif; ?>
				<div class="review-content">
					<?php echo $this->__('Review by <strong>%s</strong>', $this->htmlEscape($_review->getNickname())) ?>
					<div class="replay-box">
                      <div class="replay-bottom">
                          <div class="replay-content">
						  	<p class="r_content">
								<?php  echo $detail = nl2br($this->htmlEscape($_review->getDetail())); ?>
                            </p>
						  </div>
					  </div>
					</div>
				</div>
				<div class="clear"></div>
            </dd>
        <?php $i++; endforeach; ?>
        </dl>
        <?php echo $this->getChildHtml('toolbar') ?>
    <?php endif;?>
    <?php echo $this->getChildHtml('review_form') ?>
</div>
